package com.example.tutormanagement.controller;

import com.example.tutormanagement.pojo.Profession;
import com.example.tutormanagement.pojo.Register;
import com.example.tutormanagement.pojo.Result;
import com.example.tutormanagement.service.RegisterServie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * &#064;Date: 23/06/14-15:49
 * &#064;Description: 路由/查询 更新 插入 删除
 */
@RestController
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    private RegisterServie registerServie;

    // 获取全部信息
    @GetMapping
    public Result list() {
        List<Register> registers = registerServie.list();
        return Result.success(registers);
    }
    // 获取一行byID
    @GetMapping("/{id}")
    public Result select_row(@PathVariable String id){
        registerServie.select_row(id);
        return Result.success();
    }

    // 条件查询
    @PostMapping("/search")
    public Result search(@RequestBody Register register){
        List<Register> registers = registerServie.search(register);
        return  Result.success(registers);
    }

    // 统计职业需求次数
    @GetMapping("/count")
    public Result count(){
        List<Profession> count = registerServie.count();
        return Result.success(count);
    }


    // 新增
    @PostMapping
    public Result insert(@RequestBody Register register) {
        registerServie.insert(register);
        return Result.success();
    }

    // 修改
    @PutMapping("/{id}")
    public Result update(@RequestBody Register register, @PathVariable String id) {
        registerServie.update(register, id);
        return Result.success();
    }

    // 删除
    @DeleteMapping("/{id}")
    public Result delete( @PathVariable String id) {
        registerServie.delete(id);
        return Result.success();
    }
}
